<?php

namespace Common\Model\Cache;

class Cat extends Base
{
    public function refresh()
    {
        $menu = M("Category");
        $data = $menu->order('c_sort desc,c_id asc')->select();
        foreach ($data as $v) {
            $v['url'] = $v['type'];
            if ($v['c_pid'] > 0) {
                $v['qurl'] = RU('question/lists', array('cat' => $v['c_pid'], 'cat1' => $v['c_id']));
                $v['aurl'] = RU('article/lists', array('cat' => $v['c_pid'], 'cat1' => $v['c_id']));
                $v['burl'] = RU('bbs/lists', array('cat' => $v['c_pid'], 'cat1' => $v['c_id']));
            } else {
                $v['qurl'] = RU('question/lists', array('cat' => $v['c_id']));
                $v['aurl'] = RU('article/lists', array('cat' => $v['c_id']));
                $v['burl'] = RU('bbs/lists', array('cat' => $v['c_id']));
            }
            $cat[$v['c_id']] = $v;
        }
        $this->save($cat);
        return $cat;
    }

}